﻿using System.Linq;
using System.Web.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;
using Omu.AwesomeDemo.Infra.Dto;

namespace Omu.AwesomeDemo.WebUI.Controllers
{
    public class LookupDemoController : BaseController
    {
        private readonly IRepo<Hobby> hobbyRepo;
        private readonly IRepo<Person> personRepo;

        public LookupDemoController(IRepo<Hobby> hobbyRepo, IRepo<Person> personRepo)
        {
            this.hobbyRepo = hobbyRepo;
            this.personRepo = personRepo;
        }

        public ActionResult Index()
        {
            var input = new LookupDemoInput
                            {
                                Team = new Team {ThePerson = 13},
                                Person = 8,
                                CountryId = 7,
                                Hobbies = hobbyRepo.GetAll().Take(3).Select(o => o.Id).ToList(),
                                People = personRepo.GetAll().Skip(7).Take(2).Select(o => o.Id).ToList(),
                            };
            var h = hobbyRepo.GetAll().FirstOrDefault();
            if(h!= null) input.HobbyGuid = h.IdGuid;
            return View(input);
        }

        [HttpPost]
        public ActionResult Index(LookupDemoInput input, int[] countryId)
        {
            return View(input);
        }
    }
}